home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Source / MiscMergeKit / MME+GlobalSymbols.m < prev    next >
Encoding:
Text File  |  1995-07-11  |  2.4 KB  |  86 lines

  1. //
  2. //    MME+GlobalSymbols.m -- merge engine global symbol table handlers
  3. //        Written by Don Yacktman Copyright (c) 1995 by Don Yacktman.
  4. //                Version 1.0.  All rights reserved.
  5. //        This notice may not be removed from this source code.
  6. //
  7. //    This object is included in the MiscKit by permission from the author
  8. //    and its use is governed by the MiscKit license, found in the file
  9. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  10. //    for a list of all applicable permissions and restrictions.
  11. //    
  12.  
  13.  
  14. #import <misckit/misckit.h>
  15. #import <misckit/MiscMergeEngine.h>
  16.  
  17.  
  18. @implementation MiscMergeEngine (GlobalSymbols)
  19.  
  20. // Handling a global symbol table
  21. static MiscDictionary *globalSymbolTable = nil;
  22.  
  23. + resetGlobalSymbolTable
  24. /*" Empties the global symbol table.  Returns self.
  25. "*/
  26. {    // we don't free values--this could leak memory
  27.     if (globalSymbolTable) {
  28.         [globalSymbolTable freeObjects];
  29.         [globalSymbolTable free];
  30.     }
  31.     globalSymbolTable = [[MiscDictionary alloc] init];
  32.     return self;
  33. }
  34.  
  35. + setGlobalSymbol:name toValue:val
  36. /*" Sets the global symbol %{name} to have the value %{val}.
  37. Returns self.
  38. "*/
  39. {
  40.     if (!globalSymbolTable) [self resetGlobalSymbolTable];
  41.     [val squashSpaces]; // just to be safe
  42.     [globalSymbolTable insertKey:name value:val];
  43.     return self;
  44. }
  45.  
  46. + addDictionaryToGlobalSymbols:(MiscDictionary *)aDictionary
  47. /*" Adds the contents of %{aDictionary} to the global symbol table.
  48. Returns self.  #{%{Warning:}  This is currently unimplemented.}
  49. "*/
  50. {
  51.     // ***** iterate through dictionary and copy symbols over verbatim
  52.     if (!globalSymbolTable) [self resetGlobalSymbolTable];
  53.     return self;
  54. }
  55.  
  56. + addListToGlobalSymbols:(List *)aList
  57. /*" Adds the contents of %{aList} to the global symbol table.
  58. Returns self.  The keys for the List's contents are generated
  59. as “f0”, “f1”, and so on.
  60. "*/
  61. {
  62.     int i; id name = [MiscString new];
  63.     for (i=0; i<[aList count]; i++) {
  64.         id val = [aList objectAt:i];
  65.         [name setFromFormat:"f%d", (i+1)];
  66.         if ([val isKindOf:([MiscString class])])
  67.             [self setGlobalSymbol:name toValue:val];
  68.     }
  69.     return self;
  70. }
  71.  
  72. + (MiscString *)globalSymbolForKey:(MiscString *)name
  73. /*" Returns the value for the global symbol %{name}, if found.  Returns nil
  74. if not found.
  75. "*/
  76. {
  77.     if (!globalSymbolTable) [self resetGlobalSymbolTable];
  78.     if (!name || ![name length] || ![name stringValue]) return nil;
  79.     if ([globalSymbolTable isKey:name])
  80.         return (MiscString *)[globalSymbolTable
  81.                 valueForKey:name];
  82.     return nil; // don't have it...
  83. }
  84.  
  85. @end
  86.